package com.xl.rentkeeper.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xl.fuse.protos.viewroom.ViewOrderStatus;
import com.xl.rentkeeper.R;
import com.xl.rentkeeper.act.jilu.NotSignOrderActivity;
import com.xl.rentkeeper.act.jilu.NotViewOrderActivity;
import com.xl.rentkeeper.act.jilu.SignOrderActivity;
import com.xl.rentkeeper.act.kanfang.AffirmOrderRoomAct;
import com.xl.rentkeeper.business.OrderLogic;
import com.xl.rentkeeper.entity.Order;
import com.xl.rentkeeper.log.QLog;

import java.util.List;


/**
 * Created by Administrator on 2015/7/21.
 */
public class JiluFragment extends BaseFragment implements View.OnClickListener {
    private RelativeLayout mRLTOrder;
    private RelativeLayout mRLTNoOrder;
    private RelativeLayout mRLTNoView;
    private RelativeLayout mRLTAddInfo;
    private TextView mTVSign,mTVNotSign,mTVNotView;

    @Override
    protected View initView() {
        //获取对应的布局
        View view = View.inflate(mActivity, R.layout.fragment_more, null);

        mRLTAddInfo = (RelativeLayout) view.findViewById(R.id.rl_more_addInfo);
        mRLTOrder = (RelativeLayout) view.findViewById(R.id.rlt_order);
        mRLTNoOrder = (RelativeLayout) view.findViewById(R.id.rlt_no_order);
        mRLTNoView = (RelativeLayout) view.findViewById(R.id.rlt_no_view);
        mTVSign = (TextView) view.findViewById(R.id.tv_signed);
        mTVNotSign = (TextView) view.findViewById(R.id.tv_notsigned);
        mTVNotView = (TextView) view.findViewById(R.id.tv_notview);
        mRLTOrder.setOnClickListener(this);
        mRLTNoOrder.setOnClickListener(this);
        mRLTNoView.setOnClickListener(this);
        mRLTAddInfo.setOnClickListener(this);
        return view;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser && mTVSign!=null){
            refreshHistoryOrderCount();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshHistoryOrderCount();
    }

    public void refreshHistoryOrderCount(){
        List<Order> signList = OrderLogic.getInstance().getHistoryOrderListByStatus(ViewOrderStatus.ORDER_IS_SIGN.getValue(), true);
        String sign = getResources().getString(R.string.more_tab1);
        QLog.d(this,"sign:"+signList.size());
        if(signList.size()>0){
            mTVSign.setText(sign+"("+signList.size()+")");
        }else{
            mTVSign.setText(sign);
        }
        List<Order> nosignList = OrderLogic.getInstance().getHistoryOrderListByStatus(ViewOrderStatus.ORDER_NOT_SIGN.getValue(), true);
        QLog.d(this,"nosignList:"+nosignList.size());
        String notsign = getResources().getString(R.string.more_tab2);
        if(nosignList.size()>0){
            mTVNotSign.setText(notsign+"("+nosignList.size()+")");
        }else{
            mTVNotSign.setText(notsign);
        }
        List<Order> noviewList = OrderLogic.getInstance().getHistoryOrderListByStatus(ViewOrderStatus.ORDER_NOT_VIEW.getValue(), true);
        QLog.d(this,"noviewList:"+noviewList.size());
        String notview = getResources().getString(R.string.more_tab3);
        if(noviewList.size()>0){
            mTVNotView.setText(notview+"("+noviewList.size()+")");
        }else{
            mTVNotView.setText(notview);
        }
    }
    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.rl_more_addInfo:
                intent = new Intent(mActivity, AffirmOrderRoomAct.class);
                startActivity(intent);
                mActivity.overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
                break;
            case R.id.rlt_order:
                intent = new Intent(mActivity, SignOrderActivity.class);
                startActivity(intent);
                mActivity.overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
                break;
            case R.id.rlt_no_order:
                intent = new Intent(mActivity, NotSignOrderActivity.class);
                startActivity(intent);
                mActivity.overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
                break;
            case R.id.rlt_no_view:
                intent = new Intent(mActivity, NotViewOrderActivity.class);
                startActivity(intent);
                mActivity.overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
                break;
        }
    }

    @Override
    public void onEvent(String event, boolean ret, String errInfo,Object[] data) {

    }
}
